@extends('business/layout')
@section('content')

        <!-- Content Wrapper. Contains page content -->
    <div class="content-wrapper">

        

        <!-- Content Header (Page header) -->
        <section class="content-header">
            <h1>
                商品管理
                <small>列表</small>
            </h1>
            <ol class="breadcrumb">
                <li><a href="#"><i class="fa fa-dashboard"></i> 后台</a></li>
                <li><a href="#">商品管理</a></li>
                <li class="active">列表</li>
            </ol>
        </section>

        <!-- Main content -->
        <section class="content">
            <div class="row">
                <div class="col-xs-12">
                    <div class="box">
                        <div class="box-header">
                            <h3 class="box-title">快速查看商品列表</h3>
                        </div><!-- /.box-header -->
                        <div class="box-body">

                            @if(session('info'))
                            <div  id = 'showhidden' class="alert alert-success alert-dismissable">
                                <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
                                <h4>    <i class="icon fa fa-check"></i>提示!</h4>
                                    {{ session('info') }}
                             </div>
                             @endif
                             <script type="text/javascript">

                                 window.onload=function(){
                                    $('#showhidden').hide(3000);
                                 }

                             </script>

                             <!-- //搜索分页 -->
                        <form action = "{{ url('admin/goods/index') }}" method = 'get'>
                        {{csrf_field()}}
                            <div class = 'row'>
                                <div class = 'col-md-5'>
                                      
                                        <select class="form-control" name = 'num'>
                                            <option value = '10'
                                                @if(!empty($request['num']) && $request['num']==10)
                                                    selected = selected
                                                @endif 

                                            >10</option>
                                            <option value = '20'
                                                @if(!empty($request['num']) && $request['num']==20)
                                                    selected = selected
                                                @endif                                
                                            >20</option>
                                            <option value = '50'
                                                @if(!empty($request['num']) && $request['num']==50)
                                                    selected = selected
                                                @endif
                                            >50</option>
                                            <option value = '100'
                                                @if(!empty($request['num']) && $request['num']==100)
                                                    selected = selected
                                                @endif                
                                            >100</option>
                                            
                                        </select>
                                   
                                </div>
                                <div class = 'col-md-5 col-md-offset-2'>
                                    <div class="input-group input-group">
                                        <input class="form-control"  value = "{{ $request['keyword'] or ''}}"type="text" name = 'keyword'>
                                        <span class="input-group-btn">
                                          <button class="btn btn-info btn-flat" type="submit">搜索</button>
                                        </span>
                                    </div>
                                </div>
                            </div>
                        </form> 

                           
                        
                            <div style = 'height:20px;'></div>       
                            <table id="example2" class="table table-bordered table-hover">
                                <thead>
                                <tr>
                                    <th>ID</th>
                                    <th>商品名</th>
                                    <th>父类名称</th>
                                    <th>单价</th>
                                    <th>图片</th>
                                    <th>销量</th>
                                    <th>热度</th>
                                    <th>状态</th>
                                    <th>操作</th>
                                </tr>
                                </thead>
                                <tbody>
                                 @foreach($goods as $good)
                                <tr>

                                    <td class = 'uu'>{{ $good -> id }}</td>
                                    <td name = 'proname'>{{ $good -> proname }}</td>
                                    <td>{{ $good -> pname }}</td>
                                    <td>
                                        @if($good -> pid != 0)
                                            {{ $good -> price }}
                                        @endif
                                    </td>
                                    <td>
                                        @if($good -> pid != 0)
                                        <img src = "{{ $good -> image }}" style = "width:30px;height:30px;"></td>
                                        @endif
                                    <td>
                                        @if($good -> pid != 0)
                                            {{ $good -> sales }}
                                        @endif
                                    </td>
                                    
                                        @if($good -> pid != 0)
                                            @if( $good -> hot =='0')
                                                <td class = 'hot'><a>普通</a></td>
                                            @else
                                                <td class = 'hot'><a>热门</a></td>
                                            @endif 
                                        @else
                                           <td ></td>
                                        @endif
                                                                               
                                    
                                    
                                        @if($good -> pid != 0)    
                                            @if( $good -> is_del =='0')
                                                <td class = 'is_del'><a>上架</a></td>
                                            @else
                                                <td class = 'is_del'><a>下架</a></td>
                                            @endif
                                        @else
                                            <td><a></a></td>
                                        @endif                                        
                                    
                                    <td><a href = "{{ url('/business/goods/edit') }}/{{$good -> id}}">编辑</a> <a href = "{{ url('/business/goods/delete') }}/{{$good -> id}}">删除</a></td>
                                </tr>
                               @endforeach
                                </tbody>
                               
                            </table>
                            {{ $goods -> appends($request)-> render() }}
                        </div><!-- /.box-body -->
                    </div><!-- /.box -->

                   
                </div><!-- /.col -->
            </div><!-- /.row -->
        </section><!-- /.content -->
    </div><!-- /.content-wrapper -->
    
    <!-- 状态改变的ajax的判断 -->
    <script type="text/javascript">
        window.onload = function(){
            
           $.ajaxSetup({
                    headers: {
                        'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                    }
            });
           //是否下架的ajax
           $('.is_del').on('click',function(){
                var is_del = $(this);
                // var id = $(this).parent().children().first().html();
                var id = $(this).parent().find('.uu').html();
                
                $.post('/admin/goods/ajax-update1',{id:id},function(data){
                
                    if(data == '0')
                    {
                        is_del.html("<a>下架</a>");
                    }else if(data=='2')
                    {
                        is_del.html("<a>上架</a>");
                    }
                },'json')
            })
            $('.is_del').on('mouseover',function(){
                this.style.cursor = 'pointer';
            })

            //是否热门的ajax
            $('.hot').on('click',function(){
                var hot = $(this);
                // var id = $(this).parent().children().first().html();
                var id = $(this).parent().find('.uu').html();
                
                $.post('/admin/goods/ajax-update2',{id:id},function(data){
                    
                    if(data == '4')
                    {
                        hot.html('<a>热门</a>');
                    }else if(data=='6')
                    {
                        hot.html('<a>普通</a>');
                    }
                },'json')
            })
            $('.hot').on('mouseover',function(){
                this.style.cursor = 'pointer';
            })
        }   
    </script>
    @endsection